package com.chong.method;
import java.util.Scanner;

public class Demo7 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double num1, num2;
        char operator;
        double result = 0.0;

        System.out.println("简单计算器");
        System.out.print("请输入第一个数字: ");
        num1 = scanner.nextDouble();

        System.out.print("请输入运算符 (+, -, *, /): ");
        operator = scanner.next().charAt(0);

        System.out.print("请输入第二个数字: ");
        num2 = scanner.nextDouble();

        switch (operator) {
            case '+':
                result = num1 + num2;
                break;
            case '-':
                result = num1 - num2;
                break;
            case '*':
                result = num1 * num2;
                break;
            case '/':
                if (num2 != 0) {
                    result = num1 / num2;
                } else {
                    System.out.println("错误: 除数不能为零");
                    return; // 终止程序执行
                }
                break;
            default:
                System.out.println("错误: 无效的运算符");
                return; // 终止程序执行
        }

        System.out.println("结果: " + result);
        scanner.close();

    }
}
